﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Mechanics.*;
    import Events.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Display.*;
    import Classes.doobers.*;
    import Display.PopulationUI.*;
    import Mechanics.GameEventMechanics.*;

    public class GMEditSell extends GMEdit {

        public function GMEditSell(){
            m_uiMode = UIEvent.REMOVE;
        }
        override protected function isObjectSelectable(_arg1:GameObject):Boolean{
            return (((_arg1.isSellable()) || ((_arg1 is Doober))));
        }
        override public function enableMode():void{
            super.enableMode();
            m_cursorImage = EmbeddedArt.hud_act_remove;
        }
        override public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local3:Municipal;
            var _local4:String;
            var _local5:PopulationGateDialog;
            var _local6:MechanicMapResource;
            var _local7:RollCallDataMechanic;
            if (UI.resolveIfAssetsHaveNotLoaded(DelayedAssetLoader.GENERIC_DIALOG_ASSETS)){
                return (false);
            };
            var _local2:MapResource = (m_selectedObject as MapResource);
            if (((_local2) && ((_local2 is Municipal)))){
                _local3 = (_local2 as Municipal);
                if ((((Global.world.citySim.getPopulation() > (Global.world.citySim.getPopulationCap() - _local3.getPopulationCapYield()))) || ((Global.world.citySim.getTotalBusinesses() > (Global.world.citySim.getPopulationCap() - (Math.floor(_local3.getPopulationCapYield()) * Global.gameSettings.getNumber("businessLimitByPopulationMax"))))))){
                    if ((_local2 is Landmark)){
                        _local4 = ZLoc.t("Dialogs", "CannotSellLandmark");
                    } else {
                        _local4 = ZLoc.t("Dialogs", "CannotSellMunicipal");
                    };
                    _local5 = new PopulationGateDialog(_local4, "PopulationGate");
                    UI.displayPopup(_local5);
                    return (super.onMouseUp(_arg1));
                };
                _local6 = (_local2 as MechanicMapResource);
                _local7 = (MechanicManager.getInstance().getMechanicInstance(_local6, "rollCall", MechanicManager.ALL) as RollCallDataMechanic);
                if (_local7){
                    GameTransactionManager.addTransaction(new TClearRollCallArrays());
                };
            };
            if (((_local2) && (!(m_dragging)))){
                if ((_local2 is Doober)){
                    _local2.onPlayAction();
                } else {
                    _local2.sell();
                };
            };
            deselectObject();
            return (super.onMouseUp(_arg1));
        }

    }
}//package GameMode 
